package com.info3k.server.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;

public class Tools {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		//System.out.println(Tools.getMD5("nirmel"));
	}
	
	public static String getMD5(String s){
		try{
			MessageDigest m=MessageDigest.getInstance("MD5");
			m.update(s.getBytes(),0,s.length());
			return new BigInteger(1,m.digest()).toString(16);
		} catch (NoSuchAlgorithmException e) {
			return "";
		}
	}
	 
    public static String getRandomString(int length) {
    	String charset = "!0123456789abcdefghijklmnopqrstuvwxyz";
    	
    	Random rand = new Random(System.currentTimeMillis());
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int pos = rand.nextInt(charset.length());
            sb.append(charset.charAt(pos));
        }
        return sb.toString();
    }
}
